#!/usr/bin/env node

const Koa = require('koa');
const app = new Koa();


app.use((async (ctx,next) => {
  next();
  const cost = ctx.cost;//方案一
  //const cost = await next();//方案二
  //const cost = ctx.response.header.cost;//方案三
  console.log(`${ctx.method} ${ctx.path}`);
  //next();//next作用调用下一个中间件
}))
app.use((ctx,next) => {
  const start = Date.now();
  next();
  const end = Date.now();
  const cost = end-start;
  console.log(cost,'ms');
})
//这里就相当于中间件
app.use((ctx,next) => {
  ctx.body = 'hello world!';
  //这个body是响应体
});


app.listen(3000);
console.log('hello koa2');
